<#include "../common/header.htm">
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<li class="active"><a href="${ctx}/company/systemlist">企业管理</a></li>
		</ol>
	</section>
	<section class="content">
		<form action="${ctx}/company/systemlist" method="get" id="listForm">
			<div class="box">
				<div class="box-header">
					<div class="row">
						<div class="col-sm-9">
							<div style="display: inline-block;margin: 0 10px 0 0;">
								<label>关键字：</label>
								<select class="form-control" name="keywordType" style="display: inline-block;width: auto;">
									<option value="0" <#if keywordType?? && keywordType == 0>selected="selected"</#if> >--全部--</option>
									<option value="1" <#if keywordType?? && keywordType == 1>selected="selected"</#if> >企业名称</option>
									<option value="2" <#if keywordType?? && keywordType == 2>selected="selected"</#if> >企业ID</option>
									<#-- 
									<option value="3" <#if keywordType?? && keywordType == 3>selected="selected"</#if> >登录名</option>
									<option value="4" <#if keywordType?? && keywordType == 4>selected="selected"</#if> >网关名</option>
									<option value="5" <#if keywordType?? && keywordType == 5>selected="selected"</#if> >网关标识</option> 
									-->
								</select>
								<input name="keyword" type="text" class="form-control" value="${keyword!}" placeholder="请输入关键字" style="display: inline-block;width: 180px;margin-left: 5px;" />
							</div>
							<div style="display: inline-block;margin: 0 10px 0 0;">
								<input type="button"  class="btn btn-default btn-search" onclick="companys.query();"  value="查询" />
							</div>
							<div style="display: inline-block;">
								<input type="button"  class="btn btn-primary" onclick="companys.form();" value="新增" />
							</div>
						</div>
						
					</div>
				</div>
				<div class="box-body">
					<table class="table table-hover table-bordered table-striped table-hide">
						<thead>
							<tr>
								<th style="width:60px;">#</th>
								<th style="width:80px;">企业ID</th>
								<th style="width:150px;">企业名称</th>
								<th style="width:150px;">开户时间</th>
								<th style="width:100px;">行业类型</th>
								<th style="width:140px;">所属地区</th>
								<th style="width:60px;">通道</th>
								<th style="width:280px;">操作</th>
							</tr>
						</thead>
						<tbody>
							<#list page.content as u>
							<tr>
								<td>${page.size * page.number+u_index+1}</td>
								<td>${u.companyId!}</td>
								<td title="${u.companyName!}">
									<#if u.manageUserId??>
										<a href="${ctx}/company/detail?companyId=${u.companyId}">${u.companyName!}</a>
									<#else>
										${u.companyName!}
									</#if>
								</td>
								<td>${u.insertTime!}</td>
								<#if u.industryId?? && dict["${u.industryId}"]?? >
									<td>${dict["${u.industryId}"]!}</td>
								<#else>
									<td></td>
								</#if>
								<td>${u.address!}</td>
								<#if channelNumMap?? && channelNumMap["${u.companyId}"]??>
									<td>
										${channelNumMap["${u.companyId}"]!}
									</td>
								<#else>
									<td>0</td>
								</#if>
								<td>
									<#if u.manageUserId??>
										<a href="javascript:void(0)" onclick="companys.form('${u.companyId}')">编辑</a>
										<a href="javascript:void(0)" onclick="companys.updateTheWords('${u.companyId}')">话术管理</a>
										<#-- <a href="${ctx}/channel/list?companyId=${u.companyId}">配置线路</a> -->
										<a href="javascript:void(0)" onclick="companys.resetPwd('${u.companyId}')">重置密码</a>
										<a href="javascript:void(0)" onclick="companys.manage('${u.companyId}')">管理</a>
										<a href="javascript:void(0)" onclick="companys.channel('${u.companyId}')">通道管理</a>
									<#else>
										此公司没有管理员
									</#if>
								</td>
							</tr>
							</#list>
						</tbody>
					</table>
					<#include "../common/page.htm">
				</div>
			</div>
		</form>
	</section>
</div>

<script type="text/javascript">
	var win;
	var is_submit=false;
	var outPath = "${redirectUri}";
	
	var companys = {
		query: function () {
			$(":input[name='pageNumber']").val(0);
			$("form").submit();
		},
		form:function(id){
			if(is_submit){
				return;
			}
			is_submit=true;
			id = id?id:"";
			var title = id?"修改企业":"新增企业";
			var j = 0;
			base.getView({
				url:"${ctx}/company/systemForm?id="+id,
				success:function(result) {
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									// console.log('j='+j);
									base.validAndAjaxSubmitJson($("#addCompany"), function () {
										j = 0;
									}, function (data) {
										if (data.result == 'success') {
											$("#listForm").submit();
										} else {
											j = 0;
										}
									});
									return false;
								}
							}
						}
					})
				}
			})
		},
		resetPwd : function(companyId) {
			if(is_submit){
				return;
			}
			is_submit=true;
			var title = '重置密码';
			var j = 0;
			base.getView({
				url:"${ctx}/company/resetPassWordJump?companyId="+companyId,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#resetFormID"), $("#listForm"), function () {
										j = 0;
									});
									return false;
								}
							}
						}
					})
				}
			})
		},
		manage:function(companyId){//管理企业信息
			var url = "${ctx}/login/sysOutLogin?_t="+Math.random();
			$.ajax({
				url : url,
				type : 'post',
				dataType : 'json',
				data : {"companyId":companyId},
				success : function(data) {
					if(data!=null){
						var sign = data.sign;
						var timestamps = data.timestamps;
						// var newUrl = outPath+"login/sysOutLogin.action?_clientType=wap&sign="+sign+"&timestamps="+timestamps+"&companyId="+companyId+"&requestType=index";
						var newUrl = outPath+"#/jump?sign="+sign+"&timestamps="+timestamps+"&companyId="+companyId+"&requestType=index";
						console.log('newUrl='+newUrl);
						if(win){
							win.close();
						}
						window.open(newUrl,"_blank");
					}else{
						bootbox.alert("跳转失败,请稍后重试!");
					}
				}
			});
		},
		channel : function (companyId) {
			window.location.href = "${ctx}/channel/managelist4company?lockCompany=1&companyId="+companyId;
		},
		updateTheWords:function(companyId){//话术管理
			var url = "${ctx}/login/sysOutLogin?_t="+Math.random();
			$.ajax({
				url : url,
				type : 'post',
				dataType : 'json',
				data : {"companyId":companyId},
				success : function(data) {
					if(data!=null){
						var sign = data.sign;
						var timestamps = data.timestamps;
						//var newUrl = outPath+"login/sysOutLogin.action?_clientType=wap&sign="+sign+"&timestamps="+timestamps+"&companyId="+companyId+"&requestType=questionnaireList&fromType=1&outLoginName=${loginUser.userName!}";
						var newUrl = outPath+"#/jump?sign="+sign+"&timestamps="+timestamps+"&companyId="+companyId+"&requestType=speechTechniqueManage";
						console.log('newUrl='+newUrl);
						if(win){
							win.close();
						}
						win = window.open(newUrl,"_blank");
					}else{
						bootbox.alert("跳转失败,请稍后重试!");
					}
				},
				error:function(){
					bootbox.dialog({  
		                message: "请重新登陆！",  
		                title: "提示",  
		                buttons: {  
		                    OK: {  
		                        label: "OK",  
		                        className: "btn-primary",  
		                        callback: function () {  
		                            window.location.href="${ctx}/logout";
		                        }  
		                    }  
		                }  
		            });  
				}
			});
		},
		addTheWords:function(companyId,obj){//初始化话术
			var companyName = $(obj).attr("name");
			var title = "新增话术("+companyName+")";
			base.getView({
				url:"${ctx}/questionnaire/addTheWords?companyId="+companyId,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary"
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									copyTheWords();
									return false;
								}
							}
						}
					})
				}
			});
		},
		copy:function(){//复制话术
			base.getView({
				url:"${ctx}/questionnaire/copyTheWords",
				success:function(result){
					bootbox.dialog({
						title:"复制话术",
						message:result,
						size:"large",
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary"
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									doCopy();
									return false;
								}
							}
						}
					})
				}
			});
		}
	}
	
	$("body").on("keydown", "#listForm", function(e){
		// 兼容FF和IE和Opera
		var theEvent = e || window.event;
		var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
		if (code == 13) {
			// console.log('回车执行查询');
			companys.query();
		}
	});
</script>
<#include "../common/footer.htm">